/*
 * Created on 25.06.2006 by leck
 *
 */
package de.devisnik.eidle.util;

import org.eclipse.swt.widgets.Composite;

public abstract class ScreenWithDuration extends AbstractScreen {

	final class TimedTask implements Runnable {
		private boolean cancelled = false;

		public void cancel() {
			cancelled = true;
		}

		public void run() {
			if (!cancelled) {
				fireScreenDone();
			}
		}
	}

	private final int itsDuration;
	private TimedTask itsTimedTask;

	public ScreenWithDuration(final String name, final int durationInMillis) {
		super(name);
		itsDuration = durationInMillis;
	}

	public void createControl(final Composite parent) {
		itsTimedTask = new TimedTask();
		parent.getDisplay().timerExec(itsDuration, itsTimedTask);
	}

	public void disposeControl() {
		itsTimedTask.cancel();
	}

}
